package com.hyf.oss.controller;

import com.hyf.commonutils.fruit;
import com.hyf.oss.service.ossService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/eduoss/fileoss")
//@CrossOrigin // 跨域
@Api(description="上传头像")
public class Osscomtroller {

    @Autowired
    private ossService service;

    // 上传头像的方法
    @PostMapping
    @ApiOperation(value = "上传头像方法")
    public fruit uploadOssFile(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestParam("file") MultipartFile file) {
        // 先获取上传的文件 MultipartFile

        // 返回上传 到 oss 的路径
        String url= service.uploadFileAvatar(file);

        return fruit.ok().message("文件上传成功").data("url",url);
    }

}
